#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 4e5+10;

int val[N<<2],x[N],tot,cnt,n,q,ans[N];
struct ele{
	int id,a,b;
}e[N];
bool operator < (ele x,ele y){return x.a ^ y.a ? x.a > y.a : x.b ^ y.b ? x.b < y.b : x.id < y.id;}

int pos(int t){return lower_bound(x+1,x+tot+1,t) - x;}

int query(int xl,int xr,int o = 1,int l = 1,int r = tot){
	if(xl == l && xr == r) return val[o];
	int mid = l + r >> 1; if(xr <= mid) return query(xl,xr,o<<1,l,mid);
	else if(xl > mid) return query(xl,xr,o<<1|1,mid+1,r);
	else return max(query(xl,mid,o<<1,l,mid) , query(mid+1,xr,o<<1|1,mid+1,r));
}

void upd(int pos,int v,int o = 1,int l = 1,int r = tot){
	if(l == r) return val[o] = max(val[o],v),void(); int mid = l + r>>1;
	if(pos <= mid) upd(pos,v,o<<1,l,mid);
	else if(pos > mid) upd(pos,v,o<<1|1,mid+1,r);
	val[o] = max(val[o<<1],val[o<<1|1]);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,q = in;
	for(int i = 1;i <= n;i++){
		int a = in,b = in; x[++tot] = b;
		e[++cnt] = (ele){0,a,b};
	}
	for(int i = 1;i <= q;i++){
		int a = in,b = in; x[++tot] = b;
		e[++cnt] = (ele){i,a,b};
	}
	sort(e+1,e+cnt+1); sort(x+1,x+tot+1); tot = unique(x+1,x+tot+1) - x - 1;
	for(int i = 1;i <= cnt;i++){
		e[i].b = pos(e[i].b);
		if(e[i].id){
			ans[e[i].id] = query(1,e[i].b);
		}else{
			int val = query(1,e[i].b);
			upd(e[i].b,val + 1);
		}
	}
	for(int i = 1;i <= q;i++) printf("%d\n",ans[i]);
	return 0;
}
